package app.netant.book.tzytxt;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class TzytxtDetail extends BaseDetail {

	public TzytxtDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.tzytxt.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".main #txt.clearfix .xiazai h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("上传者");
			if(idx>0){
				title = title.substring(0,idx).trim();
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".main #txt.clearfix .fm ul li");
		for(int i=0;i<parts.size();i++){
			String tags =  parts.get(i).text();
			int idx1 = tags.indexOf("：");
			int idx2 = tags.indexOf(":");
			if(idx1>0){
				String tagName = tags.substring(0,idx1).trim();
				String tagValue = tags.substring(idx1+1).trim();
				System.out.println("【Tag】："+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}else if(idx2>0){
				String tagName = tags.substring(0,idx2).trim();
				String tagValue = tags.substring(idx2+1).trim();
				System.out.println("【Tag】："+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".main #txt.clearfix .xiazai #jj.item p");
		if(parts.size()>0){
			String memo = this.getString(parts.get(0).text());
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		
		String refer = this.netSite;
		System.out.println("【Refer】:"+refer);
		this.entity.setRefer(refer);
		
		Elements parts = this.select(".main #txt.clearfix .xiazai #down.item ul li.bd a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".main #submenu h2 a.lan");
		if(parts.size()>0){
			String type = parts.get(0).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		TzytxtDetail detail = new TzytxtDetail("http://www.tzytxt.com/txt/61311.html");
		detail.test();
	}



}
